package com.ExecutorsThreads;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

//线程池的使用原理
public class MyExecutorsThreads2 {
    public static void main(String[] args) throws InterruptedException {
//        创建线程池
        ExecutorService executorService = Executors.newCachedThreadPool();
//        创建线程
        executorService.submit(() -> {
            System.out.println(Thread.currentThread().getName() + "-----正在运行");
        });
//        开启线程等待sleep
        Thread.sleep(1000);
        executorService.submit(() -> {
            System.out.println(Thread.currentThread().getName() + "----正在运行");
        });
//        关闭线程
        executorService.shutdown();

    }
}
